package com.fingard.dsp.bank.directbank.abc02;

import com.fingard.FGBiz;
import com.fingard.constant.Format;
import com.fingard.db.JDBCHelper;
import com.fingard.dsp.bank.directbank.bankInterface.IBillPool;
import com.fingard.dsp.bank.reqrespobj.billpool.*;
import com.fingard.dsp.bank.reqrespobj.billpool.Detail.*;
import com.fingard.text.StringHelper;
import com.fingard.xml.XElement;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

import java.sql.Connection;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;

public class ABC02BillPool extends ABC02BillPoolBase implements IBillPool {
    @Override
    public RetAtsB301OperBillQry BP001_OperBill_Req(ReqB301OperBillQry p_reqB301) throws Exception {
        //电票通用申请类交易首页查询
        RetAtsB301OperBillQry retAts = new RetAtsB301OperBillQry(p_reqB301.reqHeader);
        try {
            ABC02Header header = new ABC02Header();
            header.ReqDateTime = new Date();
            header.ReqSeqNo = reqHeader.transSeqID;
            int busiType = Integer.valueOf(p_reqB301.BusiType);
            String CancelType = "";//撤销类型
            if ("1".equals(p_reqB301.QueryType)) {
                //可申请类票据查询
                switch (busiType) {
                    case 4://背书转让申请
                        header.CCTransCode = "CQRM23";
                        header.msgType = "5101";
                        break;
                    case 5://质押申请
                        header.CCTransCode = "CQRM22";
                        header.msgType = "5181";
                        break;
                    case 6://解质押申请
                        header.CCTransCode = "CQLT99";
                        header.msgType = "5191";
                        break;
                    case 10://贴现申请
                        header.CCTransCode = "CQRM31";
                        header.msgType = "5111";
                        break;
                    case 12://提示付款申请
                        header.CCTransCode = "CQRM26";
                        header.msgType = "5201";
                        break;
                    default:
                        throw new Exception("未知的业务类型：" + p_reqB301.BusiType);
                }
            } else if ("3".equals(p_reqB301.QueryType)) {
                //可撤销类票据查询
                header.CCTransCode = "CQRM25";
                header.msgType = "5041";
                switch (busiType) {
//                    case 4://背书转让申请撤销  银行说没有
//                        CancelType = "";
//                        break;
                    case 5://质押申请撤销
                        CancelType = "TRE012";
                        break;
                    case 9://背书保证撤销
                        CancelType = "TRE014";
                        break;
                    case 10://贴现申请撤销
                        CancelType = "TRE007";
                        break;
                    case 12://提示付款申请撤销
                        CancelType = "TRE015";
                        break;
                    case 13://追索通知申请撤销
                        CancelType = "TRE017";
                        break;
                    default:
                        throw new Exception("未知的业务类型：" + p_reqB301.BusiType);
                }
            }
            queryOperBill(retAts, p_reqB301, header, CancelType);//电票通用申请类交易首页查询
        } catch (Exception ex) {
            ex.printStackTrace();
            retAts = new RetAtsB301OperBillQry(p_reqB301.reqHeader);
            retAts.RespCode = "-1";
            retAts.RespInfo = ex.getMessage();
            retAts.writeBefore();
        }
        retAts.writeEnd();
        return retAts;
    }

    //电票通用申请类交易首页查询/撤销申请首页查询
    public void queryOperBill(RetAtsB301OperBillQry retAts, ReqB301OperBillQry req_B301, ABC02Header header, String CancelType) throws Exception {
        XmlTextWriter xmlWriter = new XmlTextWriter();
        writeBillPoolCommonHead(xmlWriter, header);
        xmlWriter.writeStartElement("EBQryInfo");
        xmlWriter.writeElementString("ClientIds", req_B301.ClientId);//客户ID
        xmlWriter.writeElementString("AppTyp", CancelType);//撤销申请类型
        if ("0".equals(req_B301.BillType) || StringHelper.isNullOrEmpty(req_B301.BillType)) {
            xmlWriter.writeElementString("BillTyp", "");//票据种类
        } else {
            xmlWriter.writeElementString("BillTyp", "1".equals(req_B301.BillType) ? "AC01" : "AC02");//票据种类
        }
        xmlWriter.writeElementString("IdNb", req_B301.BilNo);//票据号码
        xmlWriter.writeElementString("IssDatFr", req_B301.StartDate);//出票日期Fr
        xmlWriter.writeElementString("IssDatTo", req_B301.EndDate);//出票日期To
        xmlWriter.writeElementString("DueDatFr", req_B301.BillDateTopLimit);//到期日Fr
        xmlWriter.writeElementString("DueDatTo", req_B301.BillDateLowLimit);//到期日to
        xmlWriter.writeElementString("IssAmtFr", req_B301.BillMoneyTopLimit);//票据金额Fr
        xmlWriter.writeElementString("IssAmtTo", req_B301.BillMoneyLowLimit);//票据金额To
        xmlWriter.writeElementString("FrNam", req_B301.FrNam);//出票人名称
        xmlWriter.writeElementString("AcepNam", req_B301.AcepNam);//承兑人名称
        xmlWriter.writeElementString("ToNam", req_B301.ToNam);//收票人名称
        xmlWriter.writeElementString("CpsrProv", req_B301.CpsrProv);//出质人省市代码
        xmlWriter.writeElementString("CpsrAccNo", req_B301.CpsrAccNo);//出质人账号
        xmlWriter.writeElementString("CztnDatFr", req_B301.CztnDatFr);//质押申请日Fr
        xmlWriter.writeElementString("CztnDatTo", req_B301.CztnDatTo);//质押申请日to
        xmlWriter.writeEndDocument();

        String[] tmpStrRet = sendToBank(xmlWriter.toXmlString(), req_B301.reqHeader.transType, req_B301.reqHeader.transType);
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            if (tmpBkReader != null) {
                String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
                String tmpRetInfo = tmpBkReader.getFirstText("/ap/RespInfo");
                String tmpRetRxtInfo = tmpBkReader.getFirstText("/ap/RxtInfo");
                if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                    retAts.RespCode = "0";
                    retAts.RespInfo = tmpRetInfo;
                    retAts.writeBefore();
                    while (tmpBkReader.read("/ap/EBList/EBInfo")) {
                        RetAtsB301OperBillQryDetail reAtsDetail = new RetAtsB301OperBillQryDetail();
                        XElement readXElement = tmpBkReader.readedXElement;
                        reAtsDetail.QueryType = req_B301.QueryType;
                        reAtsDetail.BusiType = req_B301.BusiType;
                        reAtsDetail.ClientId = readXElement.getSingleTextNotNull("ClientId");//持票单位ID
                        reAtsDetail.ClientName = readXElement.getSingleTextNotNull("ClientName");//持票单位名称
                        reAtsDetail.BillNum = readXElement.getSingleTextNotNull("IdNb");//票据号码
                        reAtsDetail.BillMoney = readXElement.getSingleTextNotNull("BillAmt");//票据金额
                        String BillType = readXElement.getSingleTextNotNull("BillTyp");//票据类型
                        if (!StringHelper.isNullOrEmpty(BillType)) {
                            BillType = BillType.equals("AC01") ? "1" : "2";
                        }
                        reAtsDetail.BillType = BillType;
                        String TransFlag = readXElement.getSingleTextNotNull("TransFlg");//不可转让标识
                        if (!StringHelper.isNullOrEmpty(TransFlag)) {
                            //EM00可再转让
                            //EM01不得转让
                            TransFlag = TransFlag.equals("EM00") ? "1" : "0";
                        }
                        reAtsDetail.TransFlag = TransFlag;
                        reAtsDetail.DrawDate = readXElement.getSingleTextNotNull("IssDat");//出票日期
                        reAtsDetail.DueDate = readXElement.getSingleTextNotNull("DueDat");//到期日期
                        reAtsDetail.BillDrawer = readXElement.getSingleTextNotNull("FrNam");//出票人名称
                        reAtsDetail.DrawerAccount = readXElement.getSingleTextNotNull("FrAccNo");//出票人账号
                        reAtsDetail.HolderBillAcc = readXElement.getSingleTextNotNull("HolderMark");//当前持票人账号
                        reAtsDetail.Acceptor = readXElement.getSingleTextNotNull("AcepNam");//承兑人名称
                        reAtsDetail.Payee = readXElement.getSingleTextNotNull("ToNam");//收票人名称
                        reAtsDetail.ApplyName = readXElement.getSingleTextNotNull("CpsrNam");//出质人（质押申请人）名称
                        reAtsDetail.ReceAct = readXElement.getSingleTextNotNull("CbAccNo");//质权人账号
                        reAtsDetail.BusiNo = readXElement.getSingleTextNotNull("BusCode");//业务编号
                        if (!StringHelper.isNullOrEmpty(readXElement.getSingleTextNotNull("CollType"))) {
                            reAtsDetail.CollType = readXElement.getSingleTextNotNull("CollType").equals("CT01") ? "1" : "2";//质押类型
                        }
                        retAts.writeDetail(reAtsDetail);
                    }
                } else {
                    retAts.RespCode = "0";
                    retAts.RespInfo = "查询报错：" + StringHelper.joinNotEmpty(";", tmpRetInfo, tmpRetRxtInfo) + ";";
                    retAts.writeBefore();
                }
            } else {
                throw new Exception(tmpSbMsg.toString());
            }
        } else {
            throw new Exception(tmpStrRet[1]);
        }

    }

    //入池质押申请
    @Override
    public RetAtsB302InPoolPledge BP101_InPoolPledge_Req(ReqB302InPoolPledge p_reqB302) throws Exception {
        RetAtsB302InPoolPledge retAts = new RetAtsB302InPoolPledge(p_reqB302.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        try {
            while (p_reqB302.readRecord()) {
                //1.先判断查询的账户在本地数据库是否有对应的持票人ID
                Map<String, Object> map = JDBCHelper.execQuerySingle(conn, SELECTCLIENTID, new Object[]{p_reqB302.detail.AccountName, p_reqB302.reqHeader.bankCode});
                if (map.size() == 0) {
                    //如果没有持票人ID 则调用CQRM15 查询全量持票人ID 更新DSP数据库
                    String returnMsg = getClientId(p_reqB302.reqHeader.bankCode, p_reqB302.detail.AccountName);
                    if (!StringHelper.isNullOrEmpty(returnMsg)) {
                        retAts.RespCode = "-1";
                        retAts.RespInfo = returnMsg;
                        retAts.writeRetAtsXml(retAts);
                        return retAts;
                    } else {
                        map = JDBCHelper.execQuerySingle(conn, SELECTCLIENTID, new Object[]{p_reqB302.detail.AccountName, p_reqB302.reqHeader.bankCode});
                    }
                }
                //2.查询票据信息
                Map<String, String> collztnPropsrMap = CQRT14(p_reqB302.detail.AccountNum, p_reqB302.detail.AccountArea, "", p_reqB302.detail.BillNum);
                if (collztnPropsrMap.get("Result").equals("-1")) {
                    retAts.RespCode = "-1";
                    retAts.RespInfo = collztnPropsrMap.get("ResultMsg");
                    retAts.writeRetAtsXml(retAts);
                    return retAts;
                }

                //3.发送报文请求到银行
                XmlTextWriter writerXml = new XmlTextWriter();
                ABC02Header header = new ABC02Header();
                header.CCTransCode = "CFRT95";
                header.msgType = "5180";
                header.ReqDateTime = new Date();
                header.ReqSeqNo = getReqID();
                writeBillPoolCommonHead(writerXml, header);
                writerXml.writeStartElement("EBInfo");
                writerXml.writeElementString("ClientId", map.get("RESERVE2").toString());//持票单位ID
                writerXml.writeElementString("IdNb", p_reqB302.detail.BillNum);//票据号码
                if (!StringHelper.isNullOrEmpty(p_reqB302.detail.BillType)) {
                    writerXml.writeElementString("BillTyp", p_reqB302.detail.BillType.equals("1") ? "AC01" : "AC02");//票据种类
                } else {
                    writerXml.writeElementString("BillTyp", "", true);
                }
                writerXml.writeElementString("IssDat", collztnPropsrMap.get("IssDat"), true);//出票日期
                writerXml.writeElementString("DueDat", collztnPropsrMap.get("DueDat"), true);//到期日
                writerXml.writeEndElement();//EBInfo

                writerXml.writeStartElement("CollztnBk");
                writerXml.writeElementString("CbNam", p_reqB302.detail.PawneeName, true);//质权人名称
                writerXml.writeElementString("CbOpBnk", p_reqB302.detail.PawneeCNAPSCode, true);//质权人开户行行号
                writerXml.writeElementString("CbOpBnkNam", p_reqB302.detail.PawneeCNAPSName, true);//质权人开户行名称
                writerXml.writeEndElement();//CollztnBk

                writerXml.writeStartElement("CollztnPropsr");
                writerXml.writeElementString("CpsrNam", collztnPropsrMap.get("Nam"), true);//名称
                //CpsrTyp:RC00接入行 RC01企业 RC02人民银行 RC03被代理行 RC04被代理财务公司 RC05接入财务公司
                writerXml.writeElementString("CpsrTyp", collztnPropsrMap.get("Typ"), true);//类别
                writerXml.writeElementString("CpsrOrgCode", collztnPropsrMap.get("OrgCode"), true);//组织机构代码
                writerXml.writeElementString("CpsrOpBnk", collztnPropsrMap.get("OpBnk"), true);//开户行行号
                writerXml.writeElementString("CpsrOpBnkNam", collztnPropsrMap.get("OpBnkNam"), true);//开户行名称
                writerXml.writeElementString("CpsrConBnk", collztnPropsrMap.get("ConBnk"), true);//承接行行号
                writerXml.writeElementString("CpsrConBnkNam", collztnPropsrMap.get("ConBnkNam"), true);//承接行名称
                writerXml.writeEndElement();//CollztnPropsr
                writerXml.writeElementString("BatchNo", "", true);//批次号
                writerXml.writeElementString("Note", p_reqB302.detail.Remark, true);//备注
                writerXml.writeElementString("CollType", "CT02", true);//质押类型 CT01普通质押 CT02池融资质押
                writerXml.writeEndElement();//Hermes

                writerXml.writeStartElement("Cmp");
                if ("0".equals(p_reqB302.detail.PawneeAccount)) {
                    writerXml.writeElementString("CrProv", "", true);//省市代码
                } else {
                    writerXml.writeElementString("CrProv", getAbcAccProv(p_reqB302.detail.PawneeAccount, p_reqB302.detail.PawneeArea), true);//省市代码
                }
                writerXml.writeElementString("CrAccNo", getAbcAccNo(p_reqB302.detail.PawneeAccount), true);//接收人账号
                writerXml.writeElementString("DbProv", getAbcAccProv(p_reqB302.detail.AccountNum, p_reqB302.detail.AccountArea), true);//省市代码
//                writerXml.writeElementString("DbProv", "", true);//省市代码
                writerXml.writeElementString("DbAccNo", getAbcAccNo(p_reqB302.detail.AccountNum), true);//出质人账号
                writerXml.writeEndElement();//Cmp

                writerXml.writeElementString("Amt", p_reqB302.detail.BillMoney);//票据金额
                writerXml.writeEndDocument();

                String[] tmpStrRet = sendToBank(writerXml.toXmlString(), p_reqB302.reqHeader.transType, p_reqB302.reqHeader.transType);

                if (tmpStrRet[0].length() == 0) {
                    StringBuilder tmpSbMsg = new StringBuilder();
                    XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                    if (tmpBkReader != null) {
                        RetAtsB302InPoolPledgeDetail retAteDetail = new RetAtsB302InPoolPledgeDetail();
                        String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
                        String tmpRetInfo = tmpBkReader.getFirstText("/ap/RespInfo");
                        String tmpRetRxtInfo = tmpBkReader.getFirstText("/ap/RxtInfo");

                        retAts.RespCode = "0";
                        retAts.RespInfo = StringHelper.joinNotEmpty(";", tmpRetInfo, tmpRetRxtInfo);
                        retAteDetail.RespCode = "0";
                        retAteDetail.RespInfo = StringHelper.joinNotEmpty(";", tmpRetInfo, tmpRetRxtInfo);
                        retAteDetail.ReqSeqID = p_reqB302.detail.ReqSeqID;
                        if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                            retAteDetail.ReqSeqID = tmpBkReader.getFirstText("/ap/Hermes/Head/DealContent");
                        }
                        retAteDetail.AccountNum = p_reqB302.detail.AccountNum;
                        retAteDetail.TransState = tmpBkReader.getFirstText("/ap/Channel/AbisRespCode");
                        retAteDetail.PayInfoCode = retAteDetail.TransState;
                        retAts.wirteRetDetail(retAteDetail);
                    } else {
                        retAts.RespCode = "-1";
                        retAts.RespInfo = tmpSbMsg.toString();
                    }
                } else {
                    retAts.RespCode = "-1";
                    retAts.RespInfo = tmpStrRet[1];
                }
            }
        } catch (Exception e) {
            retAts.RespCode = "-1";
            retAts.RespInfo = e.getMessage();
        } finally {
            conn.close();
        }
        retAts.writeRetAtsXml(retAts);
        return retAts;
    }


    //解质押申请
    @Override
    public RetAtsB304ImPledge BP102_ImPledge(ReqB304Impledge p_reqB304) throws Exception {
        RetAtsB304ImPledge retAts = new RetAtsB304ImPledge(p_reqB304.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        try {
            //1.票据信息
            Map<String, String> cPropsrMap = CQRB02(p_reqB304.BillNum);
            if (cPropsrMap.get("Result").equals("-1")) {
                retAts.RespCode = "-1";
                retAts.RespInfo = cPropsrMap.get("ResultMsg");
                retAts.writeRetAtsXml(retAts);
                return retAts;
            }

            //3.发送报文请求到银行
            XmlTextWriter writerXml = new XmlTextWriter();
            ABC02Header header = new ABC02Header();
            header.CCTransCode = "CFRA18";
            header.msgType = "5190";
            header.ReqDateTime = new Date();
            header.ReqSeqNo = getReqID();
            writeBillPoolCommonHead(writerXml, header);
            writerXml.writeElementString("ClientIds", cPropsrMap.get("ClientId"), true);//持票单位ID
            writerXml.writeElementString("IdNb", p_reqB304.BillNum, true);//票据号码
            writerXml.writeElementString("BillAmt", p_reqB304.BillAmt, true);//票据金额
            writerXml.writeElementString("BillType", "1".equals(p_reqB304.BillType) ? "AC01" : "AC02", true);//票据类型
            writerXml.writeElementString("IssDat", cPropsrMap.get("IssDat"), true);//出票日期
            writerXml.writeElementString("DueDat", cPropsrMap.get("DueDat"), true);//到期日

            writerXml.writeStartElement("Dscnt");
            if (!StringHelper.isNullOrEmpty(p_reqB304.AppDate)) {
                writerXml.writeElementString("AppDat", p_reqB304.AppDate, true);//质押解除申请日期
            } else {
                writerXml.writeElementString("AppDat", Format.Date10Format.format(new Date()), true);//质押解除申请日期
            }
            writerXml.writeEndElement();//Dscnt

            writerXml.writeElementString("Note", p_reqB304.Memo, true);//备注
            writerXml.writeStartElement("CPropsr");
            writerXml.writeElementString("CpsrNam", cPropsrMap.get("Nam"), true);//质权人名称
            writerXml.writeElementString("CpsrTyp", cPropsrMap.get("Typ"), true);//质权人类别
            writerXml.writeElementString("CpsrOrgCode", cPropsrMap.get("OrgCode"), true);//质权人组织机构代码
            writerXml.writeElementString("CpsrAccNo", cPropsrMap.get("AccNo"), true);//质权人账号
            writerXml.writeElementString("CpsrOpBnk", cPropsrMap.get("OpBnk"), true);//质权人开户行行号
            writerXml.writeElementString("CpsrOpBnkNam", cPropsrMap.get("OpBnkNam"), true);//质权人开户行名称
            writerXml.writeEndDocument();

            String[] tmpStrRet = sendToBank(writerXml.toXmlString(), p_reqB304.reqHeader.transType, p_reqB304.reqHeader.transType);

            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
                    String tmpRetInfo = tmpBkReader.getFirstText("/ap/RespInfo");
                    String tmpRetRxtInfo = tmpBkReader.getFirstText("/ap/RxtInfo");
                    retAts.RespCode = "0";
                    retAts.AccountNum = p_reqB304.AccountNum;
                    retAts.ReqSeqID = p_reqB304.ReqSeqID;
                    if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                        retAts.ReqSeqID = tmpBkReader.getFirstText("/ap/Hermes/Head/DealContent");
                    }
                    retAts.RespInfo = StringHelper.joinNotEmpty(";", tmpRetInfo, tmpRetRxtInfo);
                    retAts.TransState = tmpBkReader.getFirstText("/ap/Channel/AbisRespCode");
                    retAts.PayInfoCode = retAts.TransState;
                } else {
                    retAts.RespCode = "-1";
                    retAts.RespInfo = tmpSbMsg.toString();
                }
            } else {
                retAts.RespCode = "-1";
                retAts.RespInfo = tmpStrRet[1];
            }
        } catch (Exception e) {
            retAts.RespCode = "-1";
            retAts.RespInfo = e.getMessage();
        } finally {
            conn.close();
        }
        retAts.writeRetAtsXml(retAts);
        return retAts;
    }


    @Override
    public RetAtsB305DealStateQry BP002_DealStateQry(ReqB305DealStateQry req_B305) throws Exception {
        return null;
    }

    //在池额度信息查询
    @Override
    public RetAtsB306PoolAmountQry BP003_PoolAmountQry(ReqB306PoolAmountQry p_reqB306) throws Exception {
        RetAtsB306PoolAmountQry retAts = new RetAtsB306PoolAmountQry(p_reqB306.reqHeader);
        retAts.writeStart();
        String tmpRespCode = "";
        StringBuilder tmpRespInfo = new StringBuilder();
        int successNum = 0;
        try {
            //1.先调用接口（池融资）额度查询	CQLT89（消息类型5441）
            XmlTextWriter writer = new XmlTextWriter();
            ABC02Header header = new ABC02Header();
            header.CCTransCode = "CQLT89";
            header.msgType = "5441";
            header.ReqDateTime = new Date();
            header.ReqSeqNo = reqHeader.transSeqID + "5441";
            writeBillPoolCommonHead(writer, header);
            StringBuilder clientIds = new StringBuilder();
            while (p_reqB306.readRecord()) {
                clientIds.append(p_reqB306.reqDetail.clientId).append(",");
            }
            String clienIdStr = clientIds.toString().substring(0, clientIds.lastIndexOf(","));
            String[] chienIdList = clienIdStr.split(",");//用于下面客户ID过滤（测试时候行方会返回不是查询客户ID的数据）
            writer.writeElementString("ClientIds", clienIdStr);
            writer.writeEndDocument();

            String[] tmpStrRet = sendToBank(writer.toXmlString(), p_reqB306.reqHeader.transType, p_reqB306.reqHeader.transType);

            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
                    String tmpRetInfo = tmpBkReader.getFirstText("/ap/RespInfo");
                    String tmpRetRxtInfo = tmpBkReader.getFirstText("/ap/RxtInfo");
                    if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                        retAts.respCode = "0";
                        retAts.respInfo = tmpRetInfo;
                        while (tmpBkReader.read("/ap/QuotaInfoList/QuotaInfo")) {
                            RetAtsB306PoolAmountQryDetail retAtsDetail = new RetAtsB306PoolAmountQryDetail();
                            XElement readXElement = tmpBkReader.readedXElement;// 创建读取返回报文的对象
                            String tmpClientId = readXElement.getSingleTextNotNull("ClientId");
                            if (!Arrays.asList(chienIdList).contains(tmpClientId)) {
                                continue;
                            }
                            retAtsDetail.RespCode = "0";
                            retAtsDetail.Billpoollimit = readXElement.getSingleTextNotNull("InTimeQuota");//实时额度
                            retAtsDetail.GuarRate = readXElement.getSingleTextNotNull("GuarRate");//票据抵押率
                            retAtsDetail.Usedlimit = readXElement.getSingleTextNotNull("UsedQuota");//已使用额度
                            retAtsDetail.Availablelimit = readXElement.getSingleTextNotNull("RemainQuota");//剩余额度
                            retAtsDetail.CustId = readXElement.getSingleTextNotNull("ClientId");//客户Id
                            retAtsDetail.Custname = readXElement.getSingleTextNotNull("ClientName");//成员单位名称

                            //2.调用CQRA87池融资）实时额度查询	CQRA87（消息类型5443）
                            WriteBankLogLn("调用CQRA87池融资）实时额度查询...");
                            XmlTextWriter writer2 = new XmlTextWriter();
                            header.CCTransCode = "CQRA87";
                            header.msgType = "5443";
                            header.ReqDateTime = new Date();
                            header.ReqSeqNo = reqHeader.transSeqID + "5443";
                            writeBillPoolCommonHead(writer2, header);
                            writer2.writeElementString("ClientIds", retAtsDetail.CustId);
                            writer2.writeEndDocument();

                            String[] tmpStrRet2 = sendToBank(writer2.toXmlString(), p_reqB306.reqHeader.transType, p_reqB306.reqHeader.transType + "02");


                            if (tmpStrRet2[0].length() == 0) {
                                StringBuilder tmpSbMsg2 = new StringBuilder();
                                XmlTextReader tmpBkReader2 = loadBankRespXmlReader(tmpStrRet2[1], tmpSbMsg2);
                                if (tmpBkReader2 != null) {
                                    String tmpRetCode2 = tmpBkReader2.getFirstText("/ap/RespCode");
                                    String tmpRetInfo2 = tmpBkReader2.getFirstText("/ap/RespInfo");
                                    String tmpRetRxtInfo2 = tmpBkReader2.getFirstText("/ap/RxtInfo");
                                    if (tmpRetCode2 != null && tmpRetCode2.equals("0000")) {
                                        retAtsDetail.Bailacctno = tmpBkReader2.getFirstText("/ap/QuotaInfoList/QuotaInfo/SuperviseAccount");//监管账户(保证金账户)
                                        retAtsDetail.Billremains = tmpBkReader2.getFirstText("/ap/QuotaInfoList/QuotaInfo/GuarQuota");//票据抵押额度
                                        retAtsDetail.SuperviseQuota = tmpBkReader2.getFirstText("/ap/QuotaInfoList/QuotaInfo/SuperviseQuota");//监管账户额度(保证金账户额度)
                                    } else {
                                        retAtsDetail.RespInfo = "CQRA87查询客户ID" + retAtsDetail.CustId + "报错：" + StringHelper.joinNotEmpty(";", tmpRetInfo2, tmpRetRxtInfo2) + ";";
                                    }
                                } else {
                                    retAtsDetail.RespInfo = "CQRA87查询客户ID" + retAtsDetail.CustId + "报错：" + tmpSbMsg2.toString() + ";";
                                }
                            } else {
                                retAtsDetail.RespInfo = "CQRA87查询客户ID" + retAtsDetail.CustId + "报错：" + tmpStrRet2[1] + ";";
                            }

                            retAts.writeRetDetail(retAtsDetail);
                            successNum++;
                        }//while
                    } else {
                        tmpRespCode = "-1";
                        tmpRespInfo.append("CQLT89查询报错：" + StringHelper.joinNotEmpty(";", tmpRetInfo, tmpRetRxtInfo) + ";");
                    }
                } else {
                    tmpRespCode = "-1";
                    tmpRespInfo.append("CQLT89查询报错：" + tmpSbMsg.toString() + ";");
                }
            } else {
                tmpRespCode = "-1";
                tmpRespInfo.append("CQLT89查询报错：" + tmpStrRet[1] + ";");
            }
        } catch (Exception e) {
            tmpRespCode = "-1";
            tmpRespInfo.append("CQLT89查询异常，详情见日志;");
            WriteBankLogLn("CQLT89查询异常:" + e.getMessage());
        }
        if (!tmpRespCode.equals("-1") && successNum == 0) {
            retAts.tatalcount = successNum + "";
            retAts.respCode = "0";
            retAts.respInfo = "客户号：" + bankFront.org + "没有查询到请求的客户ID的额度信息";
        } else if (tmpRespCode.equals("-1")) {
            retAts.tatalcount = successNum + "";
            retAts.respCode = "-1";
            retAts.respInfo = tmpRespInfo.toString();
        }
        retAts.writeBeforeDetail();
        retAts.writeAfterDetail();
        return retAts;
    }

    @Override
    public RetAtsB307PoolAmountAdjust BP103_PoolAmountAdjust(ReqB307PoolAmountAdjust query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB308PoolAmonutAdustQry BP004_AdjustQry(ReqB308PoolAmountAdjustQry query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB309BillApply BP104_BillApply(ReqB309BillApply query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB310ShortLoan BP105_ShortLoan(ReqB310ShortLoan query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB311AssuranceTransmit BP107_AssuranceTransmit(ReqB311AssuranceTransmit query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB312AssuranceDetail BP005_AssuracneDetail(ReqB312AssuranceDetail query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB315LoanDetail BP006_LoanDetail(ReqB315LoanDetail query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB311LoanRepay BP106_LoanRepay(ReqB311LoanRepay query) throws Exception {
        return null;
    }


    @Override
    public RetAtsB324InPoolRegister BP009_InPoolRegister(ReqB324InPoolRegister p_reqB324) throws Exception {
        //(池融资)在池票据查询
        RetAtsB324InPoolRegister retAts = new RetAtsB324InPoolRegister(p_reqB324.reqHeader);
        retAts.writeStart();

        XmlTextWriter writerXml = new XmlTextWriter();
        String tmpRespCode = "";
        StringBuilder tmpRespInfo = new StringBuilder();
        try {
            while (p_reqB324.readRecord()) {
                ABC02Header header = new ABC02Header();
                header.CCTransCode = "CQRM47";
                header.msgType = "5315";
                header.ReqDateTime = new Date();
                header.ReqSeqNo = reqHeader.transSeqID;
                writeBillPoolCommonHead(writerXml, header);
                writerXml.writeElementString("ClientIds", p_reqB324.reqDetail.ClientId);//客户ID
                writerXml.writeElementString("IdNb", p_reqB324.reqDetail.billcode);//票据号码
                if (!StringHelper.isNullOrEmpty(p_reqB324.BillType)) {
                    writerXml.writeElementString("BillTyp", p_reqB324.BillType.equals("1") ? "AC01" : "AC02");//票据种类
                } else {
                    writerXml.writeElementString("BillTyp", "", true);//票据种类
                }
                writerXml.writeElementString("BillAmtFr", p_reqB324.BillMoneyTopLimit, true);//票据金额Fr
                writerXml.writeElementString("BillAmtTo", p_reqB324.BillMoneyLowLimit, true);//票据金额To
                writerXml.writeElementString("IssDatFr", p_reqB324.OutBillBeginDate, true);//出票起始日
                writerXml.writeElementString("IssDatTo", p_reqB324.OutBillEndDate, true);//出票终止日
                writerXml.writeElementString("DueDatFr", p_reqB324.BillDateTopLimit, true);//到期起始日
                writerXml.writeElementString("DueDatTo", p_reqB324.BillDateLowLimit, true);//到期终止日
                writerXml.writeElementString("InPoolTimeFr", p_reqB324.BeginDate, true);//入池时间起始日
                writerXml.writeElementString("InPoolTimeTo", p_reqB324.EndDate, true);//入池时间到期日
                if (!StringHelper.isNullOrEmpty(p_reqB324.PayReceiveFlag)) {
                    writerXml.writeElementString("PayFlag", p_reqB324.PayReceiveFlag.equals("0") ? "DPF000" : "DPF001", true);//应收应付标志
                } else {
                    writerXml.writeElementString("PayFlag", "", true);//应收应付标志
                }

                writerXml.writeEndDocument();

                String[] tmpStrRet = sendToBank(writerXml.toXmlString(), p_reqB324.reqHeader.transType, p_reqB324.reqHeader.transType);

                if (tmpStrRet[0].length() == 0) {
                    StringBuilder tmpSbMsg = new StringBuilder();
                    XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                    if (tmpBkReader != null) {
                        String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
                        String tmpRetInfo = tmpBkReader.getFirstText("/ap/RespInfo");
                        String tmpRetRxtInfo = tmpBkReader.getFirstText("/ap/RxtInfo");
                        if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                            retAts.respCode = "0";
                            retAts.respInfo = tmpRetInfo;
                            while (tmpBkReader.read("/ap/EBList/EBInfo")) {
                                RetAtsB324InPoolRegisterDetail reAtsDetail = new RetAtsB324InPoolRegisterDetail();
                                XElement readXElement = tmpBkReader.readedXElement;
                                reAtsDetail.Account = p_reqB324.reqDetail.account;
                                reAtsDetail.Billcode = readXElement.getSingleTextNotNull("IdNb");//票据号码
                                reAtsDetail.Billamt = readXElement.getSingleTextNotNull("BillAmt");//票据金额
                                String BillType = readXElement.getSingleTextNotNull("BillTyp");//票据类型
                                if (!StringHelper.isNullOrEmpty(BillType)) {
                                    //AC01 银承   AC02 商承
                                    BillType = BillType.equals("AC01") ? "1" : "2";
                                }
                                reAtsDetail.Billtype = BillType;

                                String TransFlg = readXElement.getSingleTextNotNull("TransFlg");//不可转让标识
                                if (!StringHelper.isNullOrEmpty(TransFlg)) {
                                    //EM00可再转让   EM01不得转让
                                    TransFlg = TransFlg.equals("EM00") ? "1" : "0";
                                }
                                reAtsDetail.TransFlg = TransFlg;
                                reAtsDetail.Outdate = readXElement.getSingleTextNotNull("IssDat");//出票日期
                                reAtsDetail.Duedate = readXElement.getSingleTextNotNull("DueDat");//到期日期
                                reAtsDetail.Drawername = readXElement.getSingleTextNotNull("FrNam");//出票人名称
                                reAtsDetail.Deaweracctno = readXElement.getSingleTextNotNull("FrAccNo");//出票人账号
                                reAtsDetail.Payeename = readXElement.getSingleTextNotNull("ToNam");//收票人名称
                                reAtsDetail.Acceptor = readXElement.getSingleTextNotNull("AcepNam");//承兑人名称
                                reAtsDetail.Billstatus = readXElement.getSingleTextNotNull("BillSta");//票据状态
                                String PayFlag = readXElement.getSingleTextNotNull("PayFlag");//应收应付标志
                                if (!StringHelper.isNullOrEmpty(PayFlag)) {
                                    //DPF000应收
                                    //DPF001应付
                                    PayFlag = PayFlag.equals("DPF000") ? "0" : "1";
                                }
                                reAtsDetail.PayFlag = PayFlag;
                                reAtsDetail.InPoolTime = readXElement.getSingleTextNotNull("InPoolTime").substring(0, 10);//入池时间
                                if (!StringHelper.isNullOrEmpty(readXElement.getSingleTextNotNull("CollType"))) {
                                    reAtsDetail.CollType = readXElement.getSingleTextNotNull("CollType").equals("CT01") ? "1" : "2";//质押类型CT01:普通质押CT02:池融资质押
                                }
                                reAtsDetail.ClientId = readXElement.getSingleTextNotNull("ClientId");//持票单位ID
                                reAtsDetail.Custname = readXElement.getSingleTextNotNull("ClientName");//持票单位名称
                                retAts.writeRetDetail(reAtsDetail);
                            }
                        } else {
                            tmpRespCode = "-1";
                            if (!StringHelper.isNullOrEmpty(tmpRetInfo)) {
                                tmpRespInfo.append("(池融资)在池票据查询报错：" + tmpRetInfo + ";");
                            } else {
                                tmpRespInfo.append("(池融资)在池票据查询报错：" + tmpRetRxtInfo + ";");
                            }
                        }
                    } else {
                        tmpRespCode = "-1";
                        tmpRespInfo.append("(池融资)在池票据查询报错：" + tmpSbMsg.toString() + ";");
                    }
                } else {
                    tmpRespCode = "-1";
                    tmpRespInfo.append("(池融资)在池票据查询报错：" + tmpStrRet[1] + ";");
                }
            }
        } catch (Exception e) {
            tmpRespCode = "-1";
            tmpRespInfo.append("(池融资)在池票据查询异常，详情见日志;");
            WriteBankLogLn("(池融资)在池票据查询异常:" + e.getMessage());
        }
        if (tmpRespCode.equals("-1")) {
            retAts.respCode = "-1";
            retAts.respCode = tmpRespInfo.toString();
        }
        retAts.writeBeforeDetail();
        retAts.writeEnd();
        return retAts;
    }

    //票据交易结果查询
    @Override
    public RetAtsBP008BillStateQry BP008_BillState_Qeury(ReqBP008BillStateQry query) throws Exception {
        //票据交易结果查询，直接复用电票已经实现的CMLR34接口，如果一个接口改动，电票和票据池都要改动
        RetAtsBP008BillStateQry resp = new RetAtsBP008BillStateQry(reqHeader);
        resp.writeStart();
        while (query.readRecord()) {
            RetAtsBP008BillStateQryDetail respDetail = new RetAtsBP008BillStateQryDetail();
            try {
                ReqBP008BillStateQryDetail detail = query.detail;
                ABC02Header header = new ABC02Header();
                XmlTextWriter writer = new XmlTextWriter();
                header.CCTransCode = "CMLR34";
                header.msgType = "1035";
                header.ReqDateTime = new Date();
                header.ReqSeqNo = getReqID();
                writeBillPoolCommonHead(writer, header);


                //<BusCode>业务编号</BusCode>
                writer.writeElementString("BusCode", "");
                //<IdNb>票据号码</IdNb>
                writer.writeElementString("IdNb", detail.billNo);
                //<Typ>申请回复类型</Typ>
                //<!--操作类型 1-申请 2-签收 3-驳回 4-撤销-->
                if ("1".equals(detail.operType) || "4".equals(detail.operType)) {
                    writer.writeElementString("Typ", "ST00");
                } else if ("2".equals(detail.operType) || "3".equals(detail.operType)) {
                    writer.writeElementString("Typ", "ST01");
                }
                //<TransCode>交易代码</TransCode>
                if ("4".equals(detail.operType)) {
                    writer.writeElementString("TransCode", "TRE019");
                } else {
                    writer.writeElementString("TransCode", ELE_TRANSCODE.getNotNull(detail.busiType));
                }
                writer.writeEndElement();
                writer.writeStartElement("Cmp");
                writer.writeElementString("DbAccNo", getAbcAccNo(detail.actNum));
                writer.writeElementString("DbProv", getAbcAccProv(detail.actNum, detail.actArea));
                String dbCur = convertCurToBank(detail.billCur);
                writer.writeElementString("DbCur", StringHelper.hasAnyChar(dbCur) ? dbCur : "01");
                writer.writeEndElement();


                //发送银行
                writer.writeEndDocument();
                String[] tmpStrRet = sendToBank(writer.toXmlString());
                String tmpRespCode = "";
                String tmpRespInfo = "";

                if (tmpStrRet[0].length() == 0) {
                    StringBuilder tmpSbMsg = new StringBuilder();
                    XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                    if (tmpBkReader != null) {
                        String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
                        String tmpRetInfo = tmpBkReader.getFirstText("/ap/RespInfo");
                        String tmpRetRxtInfo = tmpBkReader.getFirstText("/ap/RxtInfo");
                        if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                            tmpRespCode = "0";
                            tmpRespInfo = tmpRetInfo;

                            respDetail.reqSeqID = detail.reqSeqID;
                            respDetail.billState = tmpBkReader.getFirstText("/ap/Hermes/BillSta");//Hermes/BillSta	票据状态
                            respDetail.billNo = detail.billNo;
//                            respDetail.busiNo = detail.reqSeqID;
                            respDetail.respCode = "0";
                            respDetail.respInfo = tmpBkReader.getFirstText("/ap/Hermes/DealResult");//Hermes/DealResult	处理结果
                            if ("2".equals(query.detail.operType) || "3".equals(query.detail.operType)) {
                                respDetail.payInfoCode = "2+" + tmpBkReader.getFirstText("/ap/Hermes/ResTyp");//Hermes/ResTyp	签收标记
                                respDetail.transState = "2+" + tmpBkReader.getFirstText("/ap/Hermes/ResTyp");//Hermes/ResTyp	签收标记
                            } else if ("4".equals(query.detail.operType)) {
                                respDetail.payInfoCode = tmpBkReader.getFirstText("/ap/Hermes/ResTyp");//Hermes/ResTyp	签收标记
                                respDetail.transState = tmpBkReader.getFirstText("/ap/Hermes/ResTyp");//Hermes/ResTyp	签收标记
//                                }
                            } else {
                                respDetail.payInfoCode = tmpBkReader.getFirstText("/ap/Hermes/ResTyp");//Hermes/ResTyp	签收标记
                                respDetail.transState = tmpBkReader.getFirstText("/ap/Hermes/ResTyp");
                            }
                        } else {
                            tmpRespCode = "-1";
                            if (!StringHelper.isNullOrEmpty(tmpRetInfo)) {
                                tmpRespInfo = tmpRetInfo;
                            } else {
                                tmpRespInfo = tmpRetRxtInfo;
                            }
                        }
                    } else {
                        tmpRespCode = "-1";
                        tmpRespInfo = tmpSbMsg.toString();
                    }
                } else {
                    tmpRespCode = "-1";
                    tmpRespInfo = tmpStrRet[1];
                }
                if ("-1".equals(tmpRespCode)) {
                    respDetail = new RetAtsBP008BillStateQryDetail();
                    respDetail.respCode = "-1";
                    respDetail.respInfo = tmpRespInfo;
                }
            } catch (Exception e) {
                respDetail.respCode = "-1";
                respDetail.respInfo = "出现异常：" + e.getMessage();
                WriteBankLogLn("出现异常:" + e.getMessage());
            }
            resp.writeDetail(respDetail);
        }
        resp.writeEnd();
        return resp;
    }

    //撤销申请
    @Override
    public RetAtsBP108BillCancSubmit BP108_BillWithdrawalReq(ReqBP108BillCancSubmit p_reqB327) throws Exception {
        RetAtsBP108BillCancSubmit retAts = new RetAtsBP108BillCancSubmit(p_reqB327.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        try {
            while (p_reqB327.readRecord()) {
                //1.撤销票据信息
                XmlTextReader billDetailReader = CQRT33(p_reqB327.detail.billNo);
                if (billDetailReader == null) {
                    retAts.writeRespCode("-1");
                    retAts.writeRespInfo("无法从银行查回撤销票据信息");
                    retAts.writeAfter();
                    return retAts;
                }

                //2.票据信息
                Map<String, String> cxlPropsrMap = CQRT14(p_reqB327.detail.actNum, p_reqB327.detail.actArea, "", p_reqB327.detail.billNo);
                if (cxlPropsrMap.get("Result").equals("-1")) {
                    retAts.writeRespCode("-1");
                    retAts.writeRespInfo(cxlPropsrMap.get("ResultMsg"));
                    retAts.writeEnd();
                    return retAts;
                }

                //3.发送报文请求到银行
                XmlTextWriter writerXml = new XmlTextWriter();
                ABC02Header header = new ABC02Header();
                header.CCTransCode = "CFRT98";
                header.msgType = "5040";
                header.ReqDateTime = new Date();
                header.ReqSeqNo = getReqID();
                writeBillPoolCommonHead(writerXml, header);
                writerXml.writeStartElement("EBInfo");
                writerXml.writeElementString("ClientId", billDetailReader.getFirstTextNotNull("/ap/Hermes/EBInfo/ClientId"));//持票单位ID
                writerXml.writeElementString("IdNb", p_reqB327.detail.billNo);//票据号码
                writerXml.writeElementString("BillTyp", billDetailReader.getFirstTextNotNull("/ap/Hermes/EBInfo/BillTyp"));//票据种类
                writerXml.writeElementString("TransFlg", billDetailReader.getFirstTextNotNull("/ap/Hermes/EBInfo/TransFlg"), true);//不得转让标记
                writerXml.writeElementString("IssDat", billDetailReader.getFirstTextNotNull("/ap/Hermes/EBInfo/IssDat"), true);//出票日期
                writerXml.writeElementString("DueDat", billDetailReader.getFirstTextNotNull("/ap/Hermes/EBInfo/DueDat"), true);//到期日
                writerXml.writeEndElement();//EBInfo

                writerXml.writeStartElement("CPDInfo");
                writerXml.writeElementString("CpdNam", billDetailReader.getFirstTextNotNull("/ap/Hermes/EBInfo/CpdNam"), true);//被撤销人名称
                writerXml.writeElementString("CpdOpBnk", billDetailReader.getFirstTextNotNull("/ap/Hermes/EBInfo/CpdOpBnk"), true);//被撤销人开户行行号
                writerXml.writeElementString("CpdOpBnkNam", billDetailReader.getFirstTextNotNull("/ap/Hermes/EBInfo/CpdOpBnkNam"), true);//被撤销人开户行名称
                writerXml.writeEndElement();//CPDInfo

                writerXml.writeStartElement("CxlPropsr");
                writerXml.writeElementString("CpNam", cxlPropsrMap.get("Nam"), true);//名称
                //CpsrTyp:RC00接入行 RC01企业 RC02人民银行 RC03被代理行 RC04被代理财务公司 RC05接入财务公司
                writerXml.writeElementString("CpTyp", cxlPropsrMap.get("Typ"), true);//类别
                writerXml.writeElementString("CpOrgCode", cxlPropsrMap.get("OrgCode"), true);//组织机构代码
                writerXml.writeElementString("CpOpBnk", cxlPropsrMap.get("OpBnk"), true);//开户行行号
                writerXml.writeElementString("CpOpBnkNam", cxlPropsrMap.get("OpBnkNam"), true);//开户行名称
                writerXml.writeElementString("CpConBnk", cxlPropsrMap.get("ConBnk"), true);//承接行行号
                writerXml.writeElementString("CpConBnkNam", cxlPropsrMap.get("ConBnkNam"), true);//承接行名称
                writerXml.writeEndElement();//CxlPropsr

                writerXml.writeElementString("BatchNo", "", true);//批次号
                writerXml.writeElementString("BussCode", billDetailReader.getFirstTextNotNull("/ap/Hermes/BussCode"), true);//业务编号
                writerXml.writeEndElement();//Hermes

                writerXml.writeStartElement("Cmp");
                writerXml.writeElementString("CrProv", "", true);//被撤销人省市代码
                writerXml.writeElementString("CrAccNo", billDetailReader.getFirstTextNotNull("/ap/Hermes/EBInfo/CpdAccNo"), true);//被撤销人账号
                writerXml.writeElementString("DbProv", "", true);//撤销人省市代码
                writerXml.writeElementString("DbAccNo", billDetailReader.getFirstTextNotNull("/ap/Hermes/EBInfo/CpAccNo"), true);//撤销人账号
                writerXml.writeEndElement();//Cmp

                writerXml.writeElementString("Amt", billDetailReader.getFirstTextNotNull("/ap/Hermes/EBInfo/BillAmt"));//票据金额
                writerXml.writeEndDocument();

                String[] tmpStrRet = sendToBank(writerXml.toXmlString(), p_reqB327.reqHeader.transType, p_reqB327.reqHeader.transType);

                if (tmpStrRet[0].length() == 0) {
                    StringBuilder tmpSbMsg = new StringBuilder();
                    XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                    if (tmpBkReader != null) {
                        RetAtsBP108BillCancSubmitDetail retAteDetail = new RetAtsBP108BillCancSubmitDetail();
                        String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
                        String tmpRetInfo = tmpBkReader.getFirstText("/ap/RespInfo");
                        String tmpRetRxtInfo = tmpBkReader.getFirstText("/ap/RxtInfo");
                        retAteDetail.respCode = "0";
                        retAteDetail.respInfo = StringHelper.joinNotEmpty(";", tmpRetInfo, tmpRetRxtInfo);
                        retAteDetail.reqSeqID = p_reqB327.detail.reqSeqID;
                        if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                            retAteDetail.reqSeqID = tmpBkReader.getFirstText("/ap/Hermes/Head/DealContent");
                        }
                        retAts.writeRespCode("0");
                        retAts.writeRespInfo(StringHelper.joinNotEmpty(";", tmpRetInfo, tmpRetRxtInfo));
                        retAteDetail.transState = tmpBkReader.getFirstText("/ap/Channel/AbisRespCode");
                        retAteDetail.payInfoCode = retAteDetail.transState;
                        retAts.writeDetail(retAteDetail);
                    } else {
                        retAts.writeRespCode("-1");
                        retAts.writeRespInfo(tmpSbMsg.toString());
                    }
                } else {
                    retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpStrRet[1]);
                }
            }
        } catch (Exception e) {
            retAts.writeRespCode("-1");
            retAts.writeRespInfo(e.getMessage());
        } finally {
            conn.close();
        }
        retAts.writeEnd();
        return retAts;
    }

    @Override
    public RetAtsBP109BillRespSubmit BP109_BillPublicrReply(ReqBP109BillRespSubmit query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB317OnlineFinancingApply BP901_OnlineFinancingApply(ReqB317OnlineFinancingApply query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB318FinancingApplyQry BP902_FinancingApplyQry(ReqB318FinancingApplyQry query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB319RebuildFile BP903_RebuildFile(ReqB319RebuildFile query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB320ConfirmApplicationContract BP904_ConfirmApplicationContract(ReqB320ConfirmApplicationContract query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB321QryFinancingApply BP905_QryFinancingApply(ReqB321QryFinancingApply query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB311AssuranceTransmit BP007_AssuranceTransmitQry(ReqB329AssuranceTransmitQry query) throws Exception {
        return null;
    }
}
